package com.example.test.fragment;

import java.util.ArrayList;
import java.util.List;

import com.example.test.BillListActivity;
import com.example.test.BilldetailActivity;
import com.example.test.R;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class UserFragment extends BaseFragment {

	@ViewInject(R.id.user_gridView)
	private GridView user_gridView;
	@ViewInject(R.id.user_icon)
	private ImageView user_icon;

	@Override
	public void initData() {
		// TODO Auto-generated method stub
		list.add("账户信息");
		list.add("历史账单");
		list.add("设置中心");
		list.add("消息通知");
		list.add("关于我们");
		list.add("一键分享");
		user_gridView.setAdapter(new GradviewAdpater());
		user_gridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				switch (position) {
				case 0:

					break;
				case 1:
                   Intent intent=new Intent(ct, BillListActivity.class);
                   startActivity(intent);
					break;
				case 2:

					break;
				case 3:

					break;
				case 4:

					break;
				case 5:

					break;
				
				default:
					break;
				}
			}
		});

	}

	// Gridview填充的字符串列表
	private List<String> list = new ArrayList<String>();
	// GridView填充图片的id
	private int[] ids = { R.drawable.icon_menu_account_n_1,
			R.drawable.icon_menu_history_n_1, R.drawable.icon_menu_set_n_1,
			R.drawable.icon_remind_n_1, R.drawable.icon_home_collect_1,
			R.drawable.icon_recommend_share_n_1 };

	private int[] ids2 = { R.color.gridcolor1, R.color.gridcolor2,
			R.color.gridcolor3, R.color.gridcolor4, R.color.gridcolor5,
			R.color.gridcolor6 };

	@Override
	public View initView(LayoutInflater inflater) {
		View view = inflater.inflate(R.layout.myuser_layout, null);
		// TODO Auto-generated method stub
		ViewUtils.inject(this, view);
		return view;
	}

	class GradviewAdpater extends BaseAdapter {

		private TextView tv_griditem;
		private TextView tv_gridtext;
		private RelativeLayout rl_bg;
		private ImageView iv_icon;

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			View view = View.inflate(ct, R.layout.grad_item_layout, null);
			iv_icon = (ImageView) view.findViewById(R.id.iv_griditem);
			iv_icon.setImageResource(ids[position]);
			tv_gridtext = (TextView) view.findViewById(R.id.tv_gridtext);
			tv_gridtext.setText(list.get(position));
			int i = position % ids2.length;
			if (i >= 6) {
				i = 6;
			}
			tv_gridtext.setTextColor(getResources().getColor(ids2[i]));
			return view;
		}

	}
}
